package com.example.waibao.dao;


//import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.waibao.entity.*;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

//@Mapper
//public interface UserMapper extends BaseMapper<User> {
//
//
//}
@Mapper
public interface UserMapper  {


    @Select("select * from sys_user")
    List<User> selectList(Object o);

    @Select("select * from sys_user where user_name = #{user_name} and status = 1 and school_id = #{school_id}")
    User selectByUserName(String user_name,int school_id);

    @Update("update user set status = 0 where id = #{id}")
    void delete_student(int id);

    @Select("select * from student where user_id = #{user_id}")
    student get_a_student(int user_id);

    @Insert("insert into sys_user(user_name,nick_name, password,phoneNumber,sex,school_id, status,user_type) values(#{user_name},#{nick_name}," +
            " #{password},#{phoneNumber},#{sex},#{school_id}, 0, 2)")
    void add_teacher(User user);

    @Select("select * from school where status = 1")
    List<school> get_school();

    @Update("update sys_user set status = 1 where id = #{id}")
    void solve_users(Long id);

    @Delete("delete from sys_user where id = #{id}")
    void delete_users(Long id);

    @Update("update student set authority = 1 where user_id = #{user_id}")
    void set_student_authority(int user_id);

    @Insert("insert into school(name) values(#{name})")
    void school_register(school school);

//    @Insert("insert into speciality(school_id, type) values (#{school_id},#{type})")
//    void set_speciality(int school_id, String type);

    @Update("update user set authority = 1 where id = #{id}")
    void set_user_authority(int id);

    @Select("select * from speciality where school_id = #{school_id}")
    List<a_speciality> get_speciality(int school_id);

//    @Insert("insert into rank_speciality_score_sum(school_id, speciality_id, sum_score, create_time) values(#{school_id}," +
//            " #{speciality_id},0,#{create_time})")
//    void set_speciality_rank(int speciality_id, Date create_time, int school_id);

    @Insert("insert into rank_speciality_score_sum(school_id, speciality_id, sum_score) values(#{school_id}," +
            " #{speciality_id},0)")
    void set_speciality_rank(int speciality_id, Date create_time, int school_id);

    @Update("update sys_user set user_name = #{user_name}, nick_name = #{nick_name}, password = #{password},phoneNumber = #{phoneNumber},sex = #{sex}" +
            " where id = #{id}")
    void update_a_user(User user);

    @Select("select password from sys_user where id = #{id}")
    String check_password(User user);

    @Select( "select user_name from sys_user where user_name = #{user_name} and school_id = #{school_id}")
    String check_username_reappear(String user_name, int school_id);

    @Select("select name from school where name = #{name}" )
    String check_school_reappear(String name);


    @Update("update student set authority = 0 where user_id = #{user_id}")
    void delete_student_authority(int user_id);

    @Update("update user set authority = 0 where id = #{id}")
    void delete_user_authority(int id);

    @Delete("delete from speciality where id = #{id}")
    void delete_speciality(int id);

    @Delete("delete from rank_speciality_score_sum where speciality_id = #{speciality_id}")
    void delete_speciality_rank(int speciality_id);

    @Update("update speciality set type = #{type} where id = #{id}")
    void update_speciality(a_speciality speciality);

    @Insert("insert into sys_user_role(user_id,role_id) values (#{user_id},1)")
    void set_authority(Long user_id);

    @Select("select * from sys_role")
    List<authority> get_all_authority();

    @Insert("insert into sys_user_role(user_id,role_id) VALUES (#{user_id},#{role_id}) " +
            "ON DUPLICATE KEY UPDATE role_id = #{role_id}")
    void set_sys_authority(int user_id, int role_id);

    @Update("update sys_user set user_type = #{user_type} where id = #{id}")
    void update_user_type(int id, int user_type);

    @Select("select name from user where id = #{id} and head_have = 1")
    String check_head_have(int id);

    @Select("select school_id from user where id = #{id}")
    int get_a_school_id(int id);

    @Delete("delete from faq where user_id = #{user_id}")
    void delete_student_faq(int user_id);
}